<template>
  <div class="background">
    <el-row :gutter="20">
      <el-col :span="4"></el-col>
      <el-col :span="16">
        <el-card class="box-card">
          <template #header>
            <div class="rightOwner">
              <div class="rightOwnerLeft">
                <el-avatar class="avatar" :size="60" :src="getUserAvatar(id)" />
                <!-- 这里要显示的是发单人的一些信息 -->
                <div class="rightOwnerInfo">
                  <span class="">{{ user.nick_name }}</span>
                  <span class="little">{{ user.age }}岁</span>
                  <span class="little">{{ user.gender }}</span>
                </div>
              </div>
              <button
                class="button"
                style="vertical-align: middle"
                @click="toChat"
              >
                <span>和Ta沟通</span>
              </button>
            </div>
          </template>
          <div class="rightInfo">
            <!-- 【！要求！】 -->
            <!--  -->
            <div class="details">
              <div class="items">
                <span class="subtitle">个性签名：</span>
                <span></span>
              </div>
              <div class="items">
                <span class="subtitle">擅长领域：</span>
              </div>
              <div class="items">
                <span class="subtitle"></span>
              </div>
              <div class="items">
                <span class="subtitle">信誉分：</span>
              </div>
              <div class="items">
                <span class="subtitle">综合分：</span>
              </div>
              <div class="items">
                <span class="subtitle">常驻城市：</span>
              </div>
              <div class="items">
                <span class="subtitle">职业：</span>
              </div>
              <div class="items">
                <span class="subtitle">简介：</span>
              </div>
              <div class="items">
                <span class="subtitle">期望薪资：</span>
              </div>
              <div class="items">
                <span class="subtitle">最新评价：</span>
              </div>
            </div>
          </div>
          <div
            class="comment_card"
            v-for="(comment, index) in comments"
            :key="index"
          >
            <div class="header">
              <div class="releaser">
                <div class="rightOwnerLeft">
                  <el-avatar
                    class="avatar"
                    :size="30"
                    :src="getUserAvatar(user_ids[index])"
                  />
                  <!-- 这里要显示的是发单人的一些信息 -->
                  <div class="releaserInfo">
                    <span>{{ releasers[index] }}</span>
                  </div>
                </div>
                <div class="order">
                  <span>订单：{{ orders[index] }}</span>
                </div>
              </div>
            </div>
            <p class="comment_info">{{ comment.comment_info }}</p>
            <div class="rate">
              <div class="rate_item">
                <span>信誉评分：</span>
                <el-rate
                  v-model="comment.score"
                  disabled
                  show-score
                  allow-half
                  text-color="#ff9900"
                  score-template="{value} points"
                />
              </div>
              <div>
                <span>综合评分：</span>

                <el-rate
                  v-model="comment.belief_score"
                  disabled
                  show-score
                  allow-half
                  text-color="#ff9900"
                  score-template="{value} points"
                />
              </div>
            </div>
            <p class="releaseTime">2023.10.12{{ comment.release_time }}</p>
          </div>
        </el-card></el-col
      >

      <el-col :span="4"></el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      src_order_id: "",
      user_id: 0,
      user_data: [],
      id: "",
      comments: [{}, {}, {}, {}, {}],
      orders: [],
      releasers: [],
      user: {
        nick_name: "",
        gender: "",
        age: "",
        belief_score: "",
      },
      user_ids: [], // 要显示头像的用户ID列表
    };
  },
  methods: {
    toChat() {
      const params = new URLSearchParams();
      params.append("sender_id", this.user_id);
      params.append("receiver_id", this.id);
      params.append("order_id", this.src_order_id);

      this.axios
        .post("http://127.0.0.1:8000/get_group/", params)
        .then((res) => {
          let group = res.data.group;
          this.$router.push("/chatPage/" + group);
        });
    },
    get_comments() {
      const params = new URLSearchParams();
      params.append("worker_id", this.id);
      this.axios
        .post("http://127.0.0.1:8000/get_comments/", params)
        .then((res) => {
          if (res.data.success) {
            this.comments = res.data.data;
            console.log(this.comments);
            console.log("看上一条");
            for (var index = 0; index < 5; index++) {
              this.user_ids.push(this.comments[index].releaser_id);
            }
            this.get_releasers();
            this.get_orders();
          }
        })
        .catch((error) => {
          console.error(error); // 输出错误信息，以便调试
        });
    },
    get_releasers() {
      const params = new URLSearchParams();
      const releasers_id = [
        this.comments[0].releaser_id,
        this.comments[1].releaser_id,
        this.comments[2].releaser_id,
        this.comments[3].releaser_id,
        this.comments[4].releaser_id,
      ];
      params.append("releasers_id", releasers_id);
      this.axios
        .post("http://127.0.0.1:8000/get_releasers/", params)
        .then((res) => {
          if (res.data.success) {
            this.releasers = res.data.data;
            console.log(this.releasers);
          }
        })
        .catch((error) => {
          console.error(error); // 输出错误信息，以便调试
        });
    },
    get_orders() {
      const params = new URLSearchParams();
      const orders_id = [
        this.comments[0].order_id,
        this.comments[1].order_id,
        this.comments[2].order_id,
        this.comments[3].order_id,
        this.comments[4].order_id,
      ];
      params.append("orders_id", orders_id);
      this.axios
        .post("http://127.0.0.1:8000/get_orders/", params)
        .then((res) => {
          if (res.data.success) {
            this.orders = res.data.data;
            console.log(this.orders);
          }
        })
        .catch((error) => {
          console.error(error); // 输出错误信息，以便调试
        });
    },
    get_customer() {
      const params = new URLSearchParams();
      params.append("customer_id", this.id);
      console.log(this.id);

      this.axios
        .post("http://127.0.0.1:8000/get_customer/", params)
        .then((res) => {
          if (res.data.success) {
            this.user = res.data.data;
            console.log(this.user);
          }
        })
        .catch((error) => {
          console.error(error); // 输出错误信息，以便调试
        });
    },

    requestAvatar() {
      this.axios.post("http://127.0.0.1:8000/userInfos/").then((res) => {
        if (res.data.success) {
          this.user_data = res.data.data;
        }
      });
    },
    getUserAvatar(customer_id) {
      for (let item of this.user_data) {
        if (item.id == customer_id) {
          return item.avatar;
        }
      }
    },
    get_self() {
      this.axios.post("http://127.0.0.1:8000/userInfo/").then((res) => {
        if (res.data.success) {
          this.user_data = res.data.data;
          for (let item of this.user_data) {
            this.user_id = item.id;
          }
        }
      });
    },
  },
  mounted() {
    this.id = this.$route.query.id;
    this.src_order_id = this.$route.query.order_id;
    console.log("来自：", this.src_order_id);
    this.get_comments();
    this.requestAvatar();
    this.get_customer();
    this.get_self();
  },
};
</script>
<style scoped>
.background {
  background: linear-gradient(rgb(255, 236, 254), white);
  font-family: sans-serif;
}

.order {
  font-style: italic;
  background-color: azure;
  padding: 3px 10px;
  font-size: 15px;
  border-radius: 5px;
}
.box-card {
  width: 100%;
  margin: 50px 0;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
  background-color: red;
}
/* 发单人 */

.little {
  color: gray;
  font-size: 15px;
}
/* 订单信息 */
.items {
  margin: 16px 0;
  font-size: 16px;
  color: #222;
  line-height: 22px;
}
.subtitle {
  margin: 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: #222;
  line-height: 22px;
}

.details p {
  font-size: 14px;
  color: #222;
  line-height: 24px;
  text-align: justify;
  white-space: pre-wrap;
  word-break: break-all;
}
/* 新增 */

.rightOwner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 20px;
}
.releaser {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 7px 7px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}
.rightOwnerLeft {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.rightOwnerInfo {
  display: flex;
  padding: 10px;
}
.releaserInfo {
  display: flex;
  padding: 10px;
}
.rightOwnerInfo span {
  margin: 0 10px;
}
.rightInfo {
  padding: 3px 23px;
}
.button {
  display: inline-block;
  border-radius: 4px;
  background-color: #666699;
  border: none;
  color: #ffffff;
  text-align: center;
  font-size: 13px;
  padding: 10px;
  width: 100px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.button span:after {
  content: "»";
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}

.button:hover span {
  padding-right: 25px;
}

.button:hover span:after {
  opacity: 1;
  right: 0;
}

.comment_card {
  margin: 20px 10%;
  box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.12);
  border-radius: 4px;
  border: 1px solid #e4e7ed;
  background-color: #ffffff;
  overflow: hidden;
  color: #303113;
  transition: 0.3s;
  padding: 20px;
}

.rate {
  display: flex;
  justify-content: space-around;
  padding: 2px;
}
.rate span {
  font-size: 14px;
  vertical-align: middle;
  color: black;
}
.rate_item {
  display: flex;
  align-items: center;
}
.comment_info {
  font-size: medium;
  font-family: cursive;
  padding: 15px 2px;
}

.releaseTime {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 2px 50px;
  font-size: small;
  color: gray;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
</style>
